{extend name="public/base" /} 
{block name="style"}<link href="__LIB__/fileinput/css/fileinput.min.css" rel="stylesheet" /> {/block}
{block name="body"}
<div class="content-tabs">
	<ol class="breadcrumb">
		<li>
			<a href="{:url('index/index')}"><i class="fa fa-home"></i></a>
		</li>
		<li>
			<a href="{:url('index')}">商品管理</a>
		</li>
		<li><strong>编辑商品</strong></li>
	</ol>
</div>
<div class="row">
	<div class="col-sm-12">
		<div class="ibox float-e-margins">
			<div class="ibox-content">
				<form id="myForm" class="form-horizontal m-t" method="post" action="{:url('edit')}">
					<input type="hidden" name="id" value="{$model.id}" />
					<!--基本信息-->
					<div class="panel panel-default">
					<div class="panel-heading"> 基本信息</div>
						<div class="panel-body">
						<div class="form-group">
							<label class="col-sm-3 control-label">商品名称：</label>
							<div class="input-group col-sm-4">
								<input type="text" id="goods_name" name="goods_name" value="{$model.goods_name}" class="form-control" />
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">商品图片：</label>
							<div class="input-group col-sm-4">
								<input type="hidden" id="thumb" name="thumb" value="{$model.thumb}"/>
								<input id="upload" name="upload" type="file" />
							</div>
						</div>
						
						
						<div class="form-group">
							<label class="col-sm-3 control-label">商品简介：</label>
							<div class="input-group col-sm-4">
								<input type="text" id="comment" name="comment" value="{$model.comment}" class="form-control" />
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">单位：</label>
							<div class="input-group col-sm-4">
								<select class="form-control" name="unit" id="unit">
									<option value="1" {if condition="$model.unit==1" } selected="selected" {/if}>瓶</option>
									<option value="2" {if condition="$model.unit==2" } selected="selected" {/if}>箱</option>
									<option value="3" {if condition="$model.unit==3" } selected="selected" {/if}>品牌</option>
								</select>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">参考销售价：</label>
							<div class="input-group col-sm-4">
								<input type="text" id="sale_price" name="sale_price" value="{$model.sale_price}" class="form-control" onkeyup="clearNoNums(this)" onafterpaste="this.value=this.value.replace(/[^\d]/g,'')"/>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">市场价：</label>
							<div class="input-group col-sm-4">
								<input type="text" id="market_price" name="market_price" value="{$model.market_price}" class="form-control" onkeyup="clearNoNums(this)" onafterpaste="this.value=this.value.replace(/[^\d]/g,'')"/>
							</div>
						</div>
						
						
						</div>
					</div>
					<!--基本信息end-->
					
					<!--设置-->
					<div class="panel panel-default">
					<div class="panel-heading"> 设置</div>
						<div class="panel-body">
						<div class="form-group wxbuy" >
							<label class="col-sm-3 control-label">图文详情：</label>
							<div class="input-group col-sm-6">
								<textarea id="content" name="content" style="height: 400p	x;">
									{$model.content}
								</textarea>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">是否赠送：</label>
							<div class="input-group col-sm-4">
                                <input name="is_zs" id="is_zs" type="checkbox" {if $model.is_zs==1}checked{/if}/>
							</div>
						</div>
						<!--商品列表-->
						<div class="panel panel-default zssp" {if $model.is_zs!=1} style="display:none" {/if}>
						<div class="panel-heading"> 商品列表</div>
							<div class="panel-body">
							<div class="example-wrap">
								<span onclick="addgoods()"><a>+添加商品</a></span>				
								<table class="table table-bordered table-hover">
									<thead>
										<tr class="long-th">
											<th>商品编码</th>
											<th>商品名称</th>
											<th>商品单位</th>
											<th>商品分类</th>
											<th>销售价(元)</th>
											<th>操作</th>
										</tr>
									</thead>
									<tbody id="goodslist" class=" text-center">
									{foreach name="goods_list" item="ad"}
										<tr class="long-th" data-id="{$model.id}">
											<td>{$ad.goods_no}</td>
											<td>{$ad.goods_name}</td>
											<td>{$ad.unit}</td>
											<td>{$ad.name}</td>
											<td>{$ad.sale_price}</td>
											<td><span  data-id="{$ad.id}" onclick="del_goods1(this)">删除</span></td>
										</tr>
									{/foreach}
									</tbody>
								</table>
							</div>
							</div>
						</div>
						<!--商品列表end-->
						</div>
					</div>
					<!--设置end-->
					
					<!--自定义属性-->
					<!--自定义属性-->
					<div class="hr-line-dashed"></div>
					<div class="form-group">
						<div class="col-sm-4 col-sm-offset-3">							
							<button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;
							<a href="{:url('index')}" class="btn btn-danger"><i class="fa fa-arrow-left"></i> 返回 </a>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
{/block} {block name="script"}
<script src="__JS__/jquery.form.js"></script>
<script src="__LIB__/validate/jquery.validate.min.js"></script>
<script src="__LIB__/validate/messages_zh.min.js"></script>
<script src="__LIB__/validate/add_validate.min.js"></script>
<script src="__LIB__/fileinput/js/fileinput.min.js"></script>
<script src="__LIB__/fileinput/js/locales/zh.js"></script>
<script src="__LIB__/ueditor/ueditor.config.js" type="text/javascript"></script>
<script src="__LIB__/ueditor/ueditor.all.js" type="text/javascript"></script>
<script>
var surl="admin/goods/index";
	setMenu(surl);
	upload_one('{$model.thumb}');
	//编辑器
	var ueditor = UE.getEditor('content');
	$(function() {
		$("#myForm").validate({
			rules: {
				goods_name: "required"
			},
			messages: {
				goods_name: ICON.error + "请输入商品名称"
			},
			submitHandler: function(form) {
				ajaxForm();
			}
		});
	});
</script>
<script>
	function clearNoNum(obj)
	{
		obj.value = obj.value.replace(/^[1-9]\d{2,}[\.]?\d*/,"100");
	   	obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符
	   	obj.value = obj.value.replace(/^\./g,"");  //验证第一个字符是数字而不是.
	   	obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的.
	   	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");	   
	}
		function clearNoNums(obj)
	{
	   	obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符
	   	obj.value = obj.value.replace(/^\./g,"");  //验证第一个字符是数字而不是.
	   	obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的.
	   	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");	   
	}
</script>
<script>
	$("input[name='wxbuy_flag']").click(function(){
		var value = document.getElementById("wxbuy_flag").checked;
		if(value == true){
			$(".wxbuy").show();
		}else if(value == false){
			$(".wxbuy").hide();
		}
	})
	
	$("input[name='bouns_flag']").click(function(){
		var value = document.getElementById("bouns_flag").checked;
		if(value == true){
			$(".bouns").show();
		}else if(value == false){
			$(".bouns").hide();
		}
	})
	
	$("input[name='stock_flag']").click(function(){
		var value = document.getElementById("stock_flag").checked;
		if(value == true){
			$(".stock").show();
		}else if(value == false){
			$(".stock").hide();
		}
	})
	
	$("input[name='is_zs']").click(function(){
		var value = document.getElementById("is_zs").checked;
		if(value == true){
			$(".zssp").show();
		}else if(value == false){
			$(".zssp").hide();
		}
	})
	
	$("input[name='member_discounttype']").click(function(){
		var value = document.getElementById("member_discounttype").checked;
		if(value == true){
			$("input[name='member_price']").attr('disabled',true);
			$("input[name='lowest_discount']").attr('disabled',false);
		}else if(value == false){
			$("input[name='lowest_discount']").attr('disabled',true);
			$("input[name='member_price']").attr('disabled',false);
		}
	})
	
	
	//选择商品
	function addgoods(){
		layer.open({		
	  	type: 2, 
	  	id: "goods_list",
	 	area: ['1050px', '550px'] ,
	 	title: '添加商品',
	 	scrollbar: false,
	  	content: '/admin/line_package/goods_list' //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
		}); 
	}
	
	function del_goods1(obj){
			var con=layer.confirm('确定删除?', function(index){
					$.ajax({
					url:"{:url('del_goods')}",
					data:{pid:$(obj).parent().parent().data("id"),gid:$(obj).data("id")},
					type:"post",
					success: function(data) {
						layer.msg(data.msg);
						if(data.code==200){
							$(obj).parent().parent().remove();
						}
					}
					})
			});
	}
	function del_goods(obj){
		$(obj).parent().parent().remove();
	}
</script>
{/block}